def prime(p):
    f = True
    for d in range(2, int(p ** 0.5)+1):
        if p % d == 0:
            f = False
            break
    return f

g = int(input())
if g < 1000 or g > 9999:
    print(0)
else:
    dgts = str(g)
    mp = 0
    for i in range(len(dgts)):
        for j in range(i + 1, len(dgts)+1):
            num = int(dgts[i:j])
            if prime(num):
                mp = max(mp, num)
    print(mp)
